package com.ihr360.cnb.module.insurance.controller;

import com.ihr360.cnb.module.insurance.model.StaffDataAuthorityCodeConstants;
import com.ihr360.cnb.module.insurance.service.StaffBenefitAggregateService;
import com.ihr360.commons.vo.PageData;
import com.ihr360.insurance.entity.request.StaffBenefitRequest;
import com.ihr360.insurance.entity.vo.StaffBenefitVo;
import com.ihr360.maven.plugin.ModuleCodeStore;
import com.ihr360.maven.plugin.annotation.FunctionDefinition;
import com.ihr360.maven.plugin.annotation.ModuleDefinition;
import com.ihr360.shared.advice.response.DisableResponseAdvice;
import com.ihr360.type.StaffStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Stone.Shi
 * @description
 * @date 2018-05-23 10:43:33.
 */
@RestController
@RequestMapping("/staffBenefits")
@ModuleDefinition(mainModuleCode = ModuleCodeStore.Module.BENEFIT_CODE,
        mainModuleName = ModuleCodeStore.Module.BENEFIT_NAME,
        subModuleCode = ModuleCodeStore.Module.Benefit.STAFF_SIHF_ARCHIVE_CODE,
        subModuleName = ModuleCodeStore.Module.Benefit.STAFF_SIHF_ARCHIVE_NAME)
@DisableResponseAdvice(disabled = false)
public class StaffBenefitAggregateController {

    @Autowired
    private StaffBenefitAggregateService staffBenefitAggregateService;

    @FunctionDefinition(functionName = "获取在职的员工社保公积金档案数据", functionCode = ModuleCodeStore.Function.VIEW)
    @RequestMapping(value = "/list/inService", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public PageData<StaffBenefitVo> getInServiceList(@RequestParam String companyId,
                                                     @RequestParam String userId,
                                                     @RequestBody StaffBenefitRequest request) {
        request.setStaffStatus(StaffStatus.IN_SERVICE);
        return staffBenefitAggregateService.getList(companyId, userId, request, StaffDataAuthorityCodeConstants.ARCHIVE_AUTHORITY_CODE_VIEW);
    }

    @FunctionDefinition(functionName = "获取离职的员工社保公积金档案数据", functionCode = ModuleCodeStore.Function.VIEW)
    @RequestMapping(value = "/list/quit", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public PageData<StaffBenefitVo> getQuitList(@RequestParam String companyId,
                                                @RequestParam String userId,
                                                @RequestBody StaffBenefitRequest request) {
        request.setStaffStatus(StaffStatus.QUIT);
        return staffBenefitAggregateService.getList(companyId, userId, request, StaffDataAuthorityCodeConstants.ARCHIVE_AUTHORITY_CODE_VIEW);
    }

    @FunctionDefinition(functionName = "保存员工的社保公积金相关数据", functionCode = ModuleCodeStore.Function.UPDATE)
    @RequestMapping(value = "/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public boolean save(@RequestParam String companyId,
                        @RequestParam String userId,
                        @RequestBody List<StaffBenefitVo> benefitVos) {
        staffBenefitAggregateService.saveBenefits(companyId, userId, benefitVos, StaffDataAuthorityCodeConstants.ARCHIVE_AUTHORITY_CODE_VIEW);
        return true;
    }

}
